var mainul=document.querySelector('main>ul')
console.log(mainul)
var xhr=new XMLHttpRequest()
xhr.open('get','http://chst.vip:1234/api/getsitenav')
xhr.send()
xhr.onreadystatechange=function(){
    if(xhr.status===200&&xhr.readyState===4){
        var x=JSON.parse(xhr.responseText).result
        console.log(x)
        var html=""
        x.forEach(item => {
            html+=` <li href=${item.navHref}>
            <img src="${item.navImg}">
            <span>${item.navTitle}</span>
        </li>`
        });
        mainul.innerHTML=html
        //给li写点击事件
        var li=document.querySelectorAll('main>ul>li')
        console.log(li)
        li.forEach((item)=>{
            var wangzhi=item.getAttribute('href')
            console.log(wangzhi)
            item.onclick=function(){
                location.href=wangzhi
            }
            
        })
    }
}
//书写返回index.html功能
var fanhui=document.querySelector('header>a')
fanhui.onclick=function(){
    location.href="../index.html"
}